package com.aeoj.clientmanagement.enums.room;

/**
 * author: ZSM
 * time: 2025-04-21 14:21
 */

import lombok.Getter;

/**
 * 房间加入状态枚举
 */
@Getter
public enum RoomJoinStatusEnum {
    /**
     * 申请中
     */
    PENDING(0, "申请中"),

    /**
     * 已通过
     */
    APPROVED(1, "通过"),

    /**
     * 已拒绝
     */
    REJECTED(2, "拒绝");

    private final Integer code;
    private final String description;

    RoomJoinStatusEnum(Integer code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 根据code获取枚举
     * @param code 状态码
     * @return 对应的枚举，找不到返回null
     */
    public static RoomJoinStatusEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (RoomJoinStatusEnum status : RoomJoinStatusEnum.values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }

    /**
     * 检查code是否有效
     * @param code 状态码
     * @return 是否有效
     */
    public static boolean isValid(Integer code) {
        return getByCode(code) != null;
    }
}
